package com.hantang.web.json.ds;

import org.apache.log4j.Logger;
 
import com.hantang.web.data.ArticleData;


public class Article {


	private long id;
	private String author;// username.
	private String category;// split by ','
	private String title;
	private String keyWords;// split by ","
	private String content;
	private long publishTime; // publish time is null. not publish.
	private int status; // 0 default; -1 deleted.
	private long updateTime;
	private String remarks;
	
	private static Logger logger = Logger.getLogger(Article.class);
	
	public static Article convertData2Json(ArticleData data, int contentSize)
	{
		if(data == null){
			return null;
			
		}
		Article po = new Article();
		
		po.setAuthor(data.getAuthor());
		po.setStatus(data.getStatus());
		po.setCategory(data.getCategory());
		
		if(contentSize > 0 && data.getContent() != null && contentSize < data.getContent().length()){
			logger.info("convertData2Json, contentSize:" + contentSize);
			po.setContent(data.getContent().substring(0, contentSize));			
		}else{
			po.setContent(data.getContent());		
		}
		
		po.setId(data.getId());
		po.setKeyWords(data.getKeyWords());
		
		if(data.getPublishTime() != null){
			po.setPublishTime(data.getPublishTime().getTime());			
		}
		
		po.setRemarks(data.getRemarks());
		po.setTitle(data.getTitle());
		if(data.getUpdateTime() != null){
			po.setUpdateTime(data.getUpdateTime().getTime());
		}
		
		return po;
	}
	
	public long getId() {
		return id;
	}
	public void setId(long id) {
		this.id = id;
	}
	public String getAuthor() {
		return author;
	}
	public void setAuthor(String author) {
		this.author = author;
	}
	public String getCategory() {
		return category;
	}
	public void setCategory(String category) {
		this.category = category;
	}
	public String getTitle() {
		return title;
	}
	public void setTitle(String title) {
		this.title = title;
	}
	public String getKeyWords() {
		return keyWords;
	}
	public void setKeyWords(String keyWords) {
		this.keyWords = keyWords;
	}
	public String getContent() {
		return content;
	}
	public void setContent(String content) {
		this.content = content;
	}
	public long getPublishTime() {
		return publishTime;
	}
	public void setPublishTime(long publishTime) {
		this.publishTime = publishTime;
	}
	public long getUpdateTime() {
		return updateTime;
	}
	public void setUpdateTime(long updateTime) {
		this.updateTime = updateTime;
	}
	public String getRemarks() {
		return remarks;
	}
	public void setRemarks(String remarks) {
		this.remarks = remarks;
	}
	public void setStatus(int status) {
		this.status = status;
	}
	public int getStatus() {
		return status;
	}
	
	
}
